
import sai.mysql.DriverLoading;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author sai
 */
public class Login extends HttpServlet {
    HttpSession session;

    public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        res.setContentType("text/html");
        PrintWriter out = res.getWriter();
        RequestDispatcher rd;
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String type = req.getParameter("type");

        try {
            DriverLoading dl = new DriverLoading();
            Statement st = dl.getStatement();
            ResultSet rs = st.executeQuery("select userid,password from `logindetails` where userid='" + username + "' and password='" + password + "'");
            boolean b = rs.next();
            if (b) {
                if (type.equals("patient")) {
                    session = req.getSession();
                    session.setAttribute("username",username);                   
                    rd = req.getRequestDispatcher("/patienthome.jsp");
                    rd.forward(req, res);                    
                    dl.close();
                } else {
                    session=req.getSession();
                    session.setAttribute("username", username);
                    rd = req.getRequestDispatcher("/doctorhome.jsp");
                    rd.forward(req, res);                   
                    dl.close();
                }
            } else {
                rd = req.getRequestDispatcher("/loginerror.html");
                rd.forward(req, res);               
                dl.close();
            }
        } catch (Exception e) {
            out.println("<center>please wait . . </center>");
        }

    }
}
